﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Mall.Cart
{
    public partial class CartDel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"] == null ? "0" : Request.QueryString["id"].ToString();
            string buylist = Request.Cookies["cart"].Value == "" ? string.Empty : Request.Cookies["cart"].Value.ToString();
            buylist = Server.UrlDecode(buylist);
            string[] buylists = buylist.Split(new char[] { ',' });
            StringBuilder str_cartn = new StringBuilder();
            string str_cart = string.Empty;
            foreach (string s in buylists)
            {

                string ido = s.Split(new string[] { "{$s$}" }, StringSplitOptions.None)[0].ToString();
                if (Convert.ToInt32(id) != Convert.ToInt32(ido))
                {
                    str_cartn.Append(s);
                    str_cartn.Append(",");
                }


            }
            str_cart = str_cartn.ToString();
            if (str_cart.Length > 0)
            {
                str_cart = str_cart.Substring(0, str_cart.Length - 1);
            }
            Response.Cookies["cart"].Value = Server.UrlEncode(str_cart);
            Response.Redirect("/cart/cart.aspx");
            //return RedirectToAction("cart", "cart");
        }
    }
}